
var newer = newer || {};
newer.gd = newer.gd || {};

newer.NaviDiv = function(o) {
	this.domNode = o.domNode;
	
	this.prt = o.prt;
	
	this.init();
};

newer.NaviDiv.prototype = {
	init: function() {
		this.domNode.html("");
		
		this.domNode.removeClass("nw-event-listener").addClass("nw-event-listener");
		this.domNode.off("nw-event").on("nw-event", $.proxy(this.nweHandler,this));
		
		this.refresh();
	}, 
	
	refresh: function() {
		switch(newer.gd.pstatus.ptype) {
			case newer.UriHelper.PEOPLE_TYPE:
				this.domNode.html("");
				this.domNode.append('<div id="posts-button-navi-div" class="navi-button">Posts</div>');
				this.domNode.append('<div id="friends-button-navi-div" class="navi-button">Friends</div>');
				this.domNode.append('<div id="circles-button-navi-div" class="navi-button">Circles</div>');
				this.domNode.append('<div id="about-button-navi-div" class="navi-button">About</div>');
				this.updatePeopleTabs();
				break;
			case newer.UriHelper.CIRCLE_TYPE:
				this.domNode.html("");
				this.domNode.append('<div id="posts-button-navi-div" class="navi-button">Posts</div>');
				this.domNode.append('<div id="members-button-navi-div" class="navi-button">Members</div>');
				this.domNode.append('<div id="about-button-navi-div" class="navi-button">About</div>');
				this.updateCircleTabs();
				break;
			default:
		}
	}, 
	
	nweHandler: function(e,c) {
		if(c.type == newer.EventHelper.PAGE_TYPE) {
			if (c.fromStatus.ptype == c.toStatus.ptype) {
				if (c.fromStatus.ptype == newer.UriHelper.PEOPLE_TYPE) {
					this.updatePeopleTabs();
				} else if (c.fromStatus.ptype == newer.UriHelper.CIRCLE_TYPE) {
					this.updateCircleTabs();
				}
			} else {
				this.refresh();
			}
		}
	},
	
	updatePeopleTabs: function() {
		this.tabs = {
			"posts-button-navi-div": "posts", 
			"friends-button-navi-div": "friends", 
			"circles-button-navi-div": "circles", 
			"about-button-navi-div": "about"
		};

		newer.TabsHelper.pressTab(
			this, 
			newer.gd.pstatus.tab+"-button-navi-div", 
			"navi-button-selected", 
			"navi-button-released", 
			this.naviButtonClickHandler, 
			this.tabs);
	},
	
	updateCircleTabs: function() {
		this.tabs = {
			"posts-button-navi-div": "posts", 
			"members-button-navi-div": "members",  
			"about-button-navi-div": "about"
		};
		newer.TabsHelper.pressTab(
			this, 
			newer.gd.pstatus.tab+"-button-navi-div", 
			"navi-button-selected", 
			"navi-button-released", 
			this.naviButtonClickHandler, 
			this.tabs);
	},
	
	naviButtonClickHandler: function(event) {
		var d = event.data;
		var s = d.self;
		newer.TabsHelper.pressTab(d.self, d.id, "navi-button-selected", "navi-button-released", s.naviButtonClickHandler, s.tabs);
		
		var fromStatus = newer.gd.pstatus;
		var toStatus = {
			ptype:newer.gd.pstatus.ptype,
			id:newer.gd.pstatus.id,
			tab:d.title
		}
		newer.UriHelper.initRedirection({
			fromStatus:fromStatus,
			toStatus:toStatus
		});
		$(".nw-event-listener").trigger('nw-event',{
			type:newer.EventHelper.PAGE_TYPE,
			fromStatus:fromStatus,
			toStatus:newer.gd.pstatus
		});	
	}
};